package com.example.translateappjava.DataBase;

import java.time.LocalDate;
import java.time.Period;

public class UserInfo {
    private int userid = 0;
    private String username = "0";
    private String password = "0";
    private String sex = "0";
    private String birth = "2025-05-29";
    private String name = "0";
    private String nickname = "0";
    private String registerDate = "2025-05-29";
    private String phoneNumber;
    private String email;
    private String height;
    private String weight;
    private String sportLevel;
    private int age = 0;
    private byte[] image;
    public static UserInfo sUserInfo;

    // 构造函数
    public UserInfo(int userid, String username, String password, String sex, String name, String nickname, String birth, String registerDate, String phoneNumber, String email, String height, String weight, String sportLevel,byte[] image) {
        this.userid = userid;
        this.username = username;
        this.password = password;
        this.sex = sex;
        this.name = name;
        this.nickname = nickname;
        this.birth = birth;
        this.registerDate = registerDate;
        this.phoneNumber = phoneNumber;
        this.email = email;
        this.height = height;
        this.weight = weight;
        this.sportLevel = sportLevel;
        this.image = image;
        calculateAge();
    }

    // 计算年龄的方法
    private void calculateAge() {
        LocalDate birthDate = LocalDate.parse(this.birth);
        LocalDate currentDate = LocalDate.now();
        this.age = Period.between(birthDate, currentDate).getYears();
    }

    // 更新用户信息的方法
    public void updateUserInfo(String username, String password, String sex, String name, String nickname, String birth, String registerDate, String phoneNumber, String email, String height, String weight, String sportLevel) {
        this.username = username;
        this.password = password;
        this.sex = sex;
        this.name = name;
        this.nickname = nickname;
        this.birth = birth;
        this.registerDate = registerDate;
        this.phoneNumber = phoneNumber;
        this.email = email;
        this.height = height;
        this.weight = weight;
        this.sportLevel = sportLevel;
        this.image = image;
        calculateAge();
    }


    public byte[] getImage() {
        return image;
    }

    public void setImage(byte[] image) {
        this.image = image;
    }

    public static UserInfo getsUserInfo() {
        return sUserInfo;
    }

    public static void setsUserInfo(UserInfo sUserInfo) {
        UserInfo.sUserInfo = sUserInfo;
    }

    // Getters and setters for all fields
    // ...
    public int getUserid() {
        return userid;
    }

    public void setUserid(int userid) {
        this.userid = userid;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getBirth() {
        return birth;
    }

    public void setBirth(String birth) {
        this.birth = birth;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public String getRegisterDate() {
        return registerDate;
    }

    public void setRegisterDate(String registerDate) {
        this.registerDate = registerDate;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getHeight() {
        return height;
    }

    public void setHeight(String height) {
        this.height = height;
    }

    public String getWeight() {
        return weight;
    }

    public void setWeight(String weight) {
        this.weight = weight;
    }

    public String getSportLevel() {
        return sportLevel;
    }

    public void setSportLevel(String sportLevel) {
        this.sportLevel = sportLevel;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

}
